package algorithm;


import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.jpbc.Field;
import it.unisa.dia.gas.jpbc.Pairing;

import java.math.BigInteger;
import java.util.Base64;

/**
 * 存储中间结果的类，E代表Element类型A代表属性，是一个String类型
 */
public class EAUnion {
    private Element eData;
    private String attribute;

    public EAUnion(Element eData, String attribute) {
        this.eData = eData;
        this.attribute = attribute;
    }


    public EAUnion() {
    }

    public Element geteData() {
        return eData;
    }

    public void seteData(Element eData) {
        this.eData = eData;
    }

    public String getAttribute() {
        return attribute;
    }

    public void setAttribute(String attribute) {
        this.attribute = attribute;
    }

    public String toString(){
        StringBuilder builder=new StringBuilder(Base64.getEncoder().encodeToString(eData.toBytes()));
        builder.append("@");
        builder.append(attribute);
        return builder.toString();
    }

    public void fromString(String input,Field G1){
        String[] splitInput=input.split("@");
        eData=G1.newElement();
        eData.setFromBytes(Base64.getDecoder().decode(splitInput[0]));
        eData=eData.getImmutable();
        attribute=splitInput[1];
    }

}
